<template>
    <view class="container" :style="{
        height: listHeight,
        background: page.BackGroundColor ? page.BackGroundColor : '',
    }">
        <header-bar :config="config"></header-bar>
        <view class="dynamic">
            <dynamic v-if="widgetList" :datas="widgetList" :listHeight="dynamicHeight"></dynamic>
        </view>
        <view class="loginPop" @click="goLogin" v-if="!token && showtime">
            <view>立即登录享更多优惠</view>
            <view class="loginBtn">立即登录</view>
        </view>
    </view>
</template>

<script>
import dynamic from "@/uni-sub-base/module/dynamic/shop/index.vue"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
import { GetPageTemplateJson } from "@/service/api/pageTemplate.js"
import { GetSignInfo, GetSignRank } from "@/service/api/user.js"
import storage from "@/uni-sub-base/utils/storage.js"
export default {
    components: {
        dynamic,
    },
    props: {
        visible: {
            type: Boolean,
            default: false,
        },
    },
    watch: {
        visible: {
            handler(newVal) {
                if (newVal) {
                    this.setStatusBarStyle("light")
                    setTimeout(() => {
                        this.getListHeight()
                        this.getDynamicHeight()
                    }, 100)
                }
            },
            immediate: true,
        },
    },
    data() {
        return {
            listHeight: "500rpx",
            dynamicHeight: "500rpx",
            page: {
                SEOTitle: "",
                BackGroundColor: "",
            },
            widgetList: null,
            config: {
                title: "首页",
                back: false,
                centerSlot: true,
                barPlaceholder: true,
                color: ["#ffffff"],
            },
            token: "",
            showtime: false,
        }
    },
    created() {
        this.config.backgroundColor = [1, this.getThemeColor]
        // GetSignInfo().then((res) => {

        // })
        // GetSignRank({ rankSize: "20", rankTime: "total" }).then((res) => {

        // })
    },
    mounted() {
        this.token = storage.getCache("token")
        this.getPageTemplateJson()
        setTimeout((e) => {
            this.showtime = true
        }, 1500)
    },
    onShow() { },
    onShareTimeline(res) {
        return {
            title: "",
            path: "",
            imageUrl: "",
            success(res) {
                uni.showToast({
                    title: "分享成功",
                })
            },
            fail(res) {
                uni.showToast({
                    title: "分享失败",
                    icon: "none",
                })
            },
        }
    },
    methods: {
        getListHeight() {
            //获取商品高度
            getElementHeight(this, ".container", (e) => {
                this.listHeight = e - 54 + "px"
            })
        },
        getDynamicHeight() {
            //获取商品高度
            getElementHeight(this, ".dynamic", (e) => {
                this.dynamicHeight = e - 54 + "px"
            })
        },
        getPageTemplateJson() {
            let param = {
                pageType: 4,
            }
            let AppIndexID = storage.getCache("AppIndexID")
            let path = `?pageType=4`
            if (AppIndexID) {
                path = `?pageType=4&id=` + AppIndexID
            }
            GetPageTemplateJson(param, path).then((res) => {
                if (res.Data) {
                    try {
                        let obj = JSON.parse(res.Data)
                        this.page.BackGroundColor = obj.BackGroundColor
                        this.page.SEOTitle = obj.SEOTitle
                        this.widgetList = obj.WidgetList
                        console.log("首页装修", this.widgetList)
                        //设置标题
                        if (this.page.SEOTitle) {
                            this.config.title = this.page.SEOTitle
                        }
                        // setTimeout(e=>{
                        // 	storage.removeCache('AppIndexID');
                        // },1000)
                    } catch (e) {
                        console.log(e)
                    }
                }
            })
        },
        goLogin() {
            let url = "/pages/login/loading?goLogin=true"
            uni.reLaunch({
                url: url,
            })
        },
    },
}
</script>

<style lang="scss">
.loginPop {
    width: 702rpx;
    height: 92rpx;
    background: rgba(0, 0, 0, 0.69);
    border-radius: 46rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    left: 24rpx;
    bottom: 120rpx;
    z-index: 100;

    view {
        font-size: 32rpx;
        // font-weight: bold;
        color: #fff;
        margin-left: 44rpx;
    }

    .loginBtn {
        width: 188rpx;
        height: 68rpx;
        background: $app-color-main;
        border-radius: 34rpx;
        font-size: 28rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 16rpx;
    }
}
</style>
